/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.exception.mapper.ExceptionEntityMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.exception.mapper;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.ucf.mdf.app.isvdxq.exception.entity.ExceptionEntity;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ExceptionEntityMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;

    public List<ExceptionEntity> selectPage(String tenantId, int m, int n) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_exceptions where `ytenant_id` = ? limit ?,?;";
        parameter.addParam(tenantId);
		parameter.addParam(m);
		parameter.addParam(n);

        ResultSetProcessor processor = new AutoBeanListProcessor(new ExceptionEntity());
        return (List<ExceptionEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public List<ExceptionEntity> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from dxq_exceptions where 1=1 ");
		if (tenantId != null && !"".equals(tenantId)) {
			sqlBuilder.append(" and `ytenant_id` = ? ");
			parameter.addParam(tenantId);
		}
		sqlBuilder.append(" ; ");

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new ExceptionEntity());
        return (List<ExceptionEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public int InsertException(String exceptionStr, String exceptionModel, String appVersion, String deviceID, String systemVersion, String systemModel, String deviceBrand, String pixels, String ip, String fk_userID, String id, String tenant_id, int source, String remark) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "INSERT INTO `dxq_exceptions` (`exception`,`exceptionModel`,`appVersion`,deviceID,`systemVersion`, systemModel, deviceBrand,pixels,ip,fk_userID,creator,modifier,`create_time`,modify_time,id,ytenant_id, `source`,`remark`)  values (?,?,?,?,?,?, ?,?,?,?,?,?,now(),now(),?,?, ?,?)\n";
        parameter.addParam(exceptionStr);
		parameter.addParam(exceptionModel);
		parameter.addParam(appVersion);
		parameter.addParam(deviceID);
		parameter.addParam(systemVersion);
		parameter.addParam(systemModel);
		parameter.addParam(deviceBrand);
		parameter.addParam(pixels);
		parameter.addParam(ip);
		parameter.addParam(fk_userID);
		parameter.addParam(fk_userID);
		parameter.addParam(fk_userID);
		parameter.addParam(id);
		parameter.addParam(tenant_id);
		parameter.addParam(source);
		parameter.addParam(remark);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public ExceptionEntity selectById(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_exceptions where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new ExceptionEntity());
        return (ExceptionEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

}
